package cn.shopping.controller.product;

import java.util.Date;
import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import cn.shopping.pojo.Sh_product;
import cn.shopping.pojo.Sh_two;
import cn.shopping.pojo.Sh_zone;
import cn.shopping.service.prouct.ProuctService;

@Controller
@RequestMapping(value="/prouct")
public class ProuctController {
	
	
	@Resource
	private ProuctService prouctservice;
	
	@RequestMapping(value="prouct_list.html")
	public String prouct_list(
			@RequestParam(value="product_name",required=false) String product_name,
			@RequestParam(value="two_name",required=false) String two_name ,
			@RequestParam(value="product_startday",required=false) Date product_startday,
			@RequestParam(value="product_modifyday",required=false) Date product_modifyday,
			Model model){
		
		List<Sh_product> list = prouctservice.prouct_list(product_name,two_name,product_startday,product_modifyday);
		
		model.addAttribute("list", list);
		return "chanpinzhuanqu";
	}
	
	
	@RequestMapping(value="zone_prouct_list.html")
	public String zone_prouct_list(@RequestParam(value="product_zone") Integer product_zone,Model model,HttpSession session){
		List<Sh_product> list = prouctservice.zone_prouct_list(product_zone);
		
		//session.setAttribute("zoneSession",product_zone);
		model.addAttribute("list", list);
		return "chanpinzhuanqu";
		
	}
	
	
	
	@RequestMapping(value="del_product.html")
	public String del_product(@RequestParam Integer id ){
		if (prouctservice.del_product(id)==1) {
			return "redirect:/prouct/prouct_list.html";
		}
		return "redirect:/prouct/prouct_list.html";
	}
	
	
	@RequestMapping(value="two_type",method=RequestMethod.GET)
	@ResponseBody
	public List<Sh_two> two_type(){
		List<Sh_two> list = prouctservice.get_twoType();
		return list;
	}
	@RequestMapping(value="zone_type",method=RequestMethod.GET)
	@ResponseBody
	public List<Sh_zone> zone_type(){
		List<Sh_zone> list = prouctservice.get_zone_Type();
		return list;
	}
	
	
	

}
